package com.hiwan.unions.util;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.hiwan.unions.R;


/**
 * Created by llg on 2017/6/6.
 */

public class ToastUtils {
    private static Toast mToast;

    //自定义提示
    public static void showToast(Context context, String charSequence) {
        if (CheckUtils.isEmpty(charSequence))
            return;
        View mView = LayoutInflater.from(context).inflate(
                R.layout.view_tips, null);
        TextView tv = (TextView) mView.findViewById(R.id.tips_msg);
        tv.setText(charSequence);
        if (mToast == null) {
            mToast = new Toast(context);
        }
        mToast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        if (charSequence.length() > 15) {
            mToast.setDuration(Toast.LENGTH_LONG);
        } else {
            mToast.setDuration(Toast.LENGTH_SHORT);
        }
        mToast.setView(mView);
        mToast.show();
    }

    //自定义提示
    public static void showToast() {
        try {
            if (mToast != null) {
                mToast.cancel();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
